//
//  WithdrawViewController.swift
//  cxd4iphone
//
//  Created by hexy on 11/25/15.
//  Copyright © 2015 hexy. All rights reserved.
//

import UIKit

private struct kConstraints {
    
    static let headerHeight: CGFloat = xx_screenHeight() - 64
    static let headerRect: CGRect    = CGRectMake(0, 0, xx_screenWidth(), kConstraints.headerHeight)
    static let footerHeight: CGFloat = xx_screenHeight() - kConstraints.headerHeight - 64 - 49
    static let footerRect: CGRect    = CGRectMake(0, 0, xx_screenWidth(), kConstraints.footerHeight)
}

class WithdrawViewController: BaseTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    override func makeTableView() {
        
        tableView.tableHeaderView = withdrawView
        
        withdrawView.nextBtn.rac_signalForControlEvents(.TouchUpInside).subscribeNext { (_) -> Void in
            
            if let money = self.withdrawView.textField.text {
                
                
                YPRequestViewModel.shared.withdraw(money).subscribeError({ (error) -> Void in
                    
                    xx_showError(error)
                    
                    }, completed: { () -> Void in
                        
                        let vc = WebViewController(title: "提现", htmlStr: YPRequestViewModel.shared.html)
                        
                        self.navigationController?.pushViewController(vc, animated: true)
                })
            }

        }
        
    }
    
    lazy var withdrawView = WithdrawView(frame: kConstraints.headerRect)
}
